import 'package:Smart/commons/shared_preferences/local_storage.dart';
import 'package:flutter/material.dart';
//颜色配置路径
import 'package:Smart/pages/productor008/project/res/res_colors.dart';
//图标图片配置路径
import 'package:Smart/pages/productor008/project/res/res_url.dart';

import 'package:flutter/rendering.dart';
import 'package:Smart/utils/screen_unit/gs_screen_util.dart';
//蓝牙弹框按钮布局
import 'package:Smart/pages/productor008/project/widget/gs_blebutton_widget.dart';
//打电话
import 'package:Smart/pages/productor008/project/util/gs_call_util.dart';

// import 'package:flutter_screenutil/flutter_screenutil.dart';


/*
 * Widget message:弹框中间的文字
  String cancelText = "取消",取消按钮的文本默认
  String confirmText = "",确认按钮
  String imagePath = "", 弹框顶部图片路径
  bool showCehckbox = false,显示/不显示复选框
  onCancel(),点击取消按钮触发的事件
  onConfirm(bool checkboxValue)点击确认按钮触发的事件
 * 
 */
///蓝牙钥匙相关对话框（激活步骤，登录失效，使用条件，一键呼叫）
class GSBluetoothCallDialog {
  /// 两个按钮：弹框一个有取消xxx和确认xxx的蓝牙弹框
  static showCancelAndConfirm(BuildContext context,
      {@required Widget message,
      String cancelText = "",
      String confirmText = "",
      String imagePath = "",
      bool showCheckbox = false,//有没有复选框
      onCancel(),
      onConfirm(bool checkboxValue)}) {
      bool checked = false;
      showDialog(
          context: context,
          builder: (BuildContext context) {
          return Scaffold(
            backgroundColor: Colors.transparent,
            body: Center(
              child: Container(
                  child: Stack(
                alignment: Alignment.center,
                children: [
                  Container(
                      height: 321.w,
                      width: 314.w,
                      margin: EdgeInsets.symmetric(vertical: 140.w),
                      padding: EdgeInsets.only(
                          left: 12.w, right: 12.w, bottom: 24.w),
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(10.w),
                      ),
                      child: Container(
                        // margin: EdgeInsets.only(top: 69.w),
                        child: Column(
                          mainAxisSize: MainAxisSize.min,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            //蓝牙弹框文字部分
                            message,
                            //可选框
                            _checkboxWidget(showCheckbox),
                            //蓝牙弹框按钮
                            Container(
                              padding: EdgeInsets.only(top: 29.w),
                              child: Row(
                                mainAxisSize: MainAxisSize.min,
                                children: [
                                  //蓝牙弹框取消按钮
                                  GSBleButtonUtil().bleCallButton(cancelText,
                                      width: 137.w, height: 44.w, onTap: () {
                                    Navigator.of(context).pop();
                                    if (onCancel != null) onCancel();
                                  }),
                                  SizedBox(width: 14.w),
                                  //蓝牙弹框确认按钮
                                  GSBleButtonUtil().bleCallButton(
                                    confirmText,
                                    width: 137.w,
                                    height: 44.w,
                                    selected: true,
                                    onTap: () {
                                      if (onConfirm != null) onConfirm(checked);
                                      Navigator.of(context).pop();
                                    },
                                  )
                                ],
                              ),
                            )
                          ],
                        ),
                      )),
                  //蓝牙弹框顶部居中图片
                  _blueToothTopImg(context, imagePath),

                  //蓝牙弹框底部的关闭按钮
                  _blueToothClose(context),
                ],
              )),
            ),
          );
        });
  }

  /// 只有一个按钮：弹框按钮为'我知道了'的弹框
  static showOnlyConfirm(BuildContext context,
      {@required Widget message,
      String knowText = "我知道了",
      String imagePath = "",
      bool showCehckbox = false,
      onConfirm(bool checkboxValue)}) {
    bool checked = false;
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return Scaffold(
            backgroundColor: Colors.transparent,
            body: Center(
              child: Container(
                  child: Stack(
                alignment: Alignment.center,
                children: [
                  Container(
                    margin: EdgeInsets.symmetric(vertical: 140.w),
                    padding:
                        EdgeInsets.only(left: 28.w, right: 28.w, bottom: 24.w),
                    height: 272.w,
                    width: 314.w,
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(10.w),
                    ),
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        //弹框文字部分
                        message,
                        //可选框
                        _checkboxWidget(showCehckbox),
                        //弹框'我知道了'按钮
                        Container(
                          // padding: EdgeInsets.only(top: 20.w),
                          alignment: Alignment.center,
                          //弹框'我知道了'按钮
                          child: GSBleButtonUtil().bleCallButton(knowText,
                              width: 258.w,
                              height: 44.w,
                              selected: true, onTap: () {
                            Navigator.of(context).pop();
                            if (onConfirm != null) onConfirm(checked);
                          }),
                        )
                      ],
                    ),
                  ),

                  //弹框顶部居中图片
                  _blueToothTopImg(context, imagePath),

                  //弹框底部的关闭按钮
                  _blueToothClose(context),
                ],
              )),
            ),
          );
        });
  }

  /// 一键呼叫客服电话，取消的弹框
  static showCallAndCancel(BuildContext context,
      {
        @required Widget message,
        String cancelText = "取消",
        // String confirmText = "客服电话 400-123-456",
        String phoneNum = "400-123-456",
        String imagePath = "",
        Function onCancel,
        Function onConfirm,
      }) {
      showDialog(
          context: context,
          builder: (context) {
          return Container(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                Container(
                  child: GSBleButtonUtil().bleCallButton("客服电话 $phoneNum",
                      width: 278.w, height: 48.w, selected: true, onTap: () {
                    if(onConfirm!=null)
                      onConfirm();
                  }),
                ),
                Container(
                  alignment: Alignment.center,
                  margin: EdgeInsets.only(top: 24.w,bottom: 38.w),
                  child: GSBleButtonUtil().bleCallButton(cancelText,
                      width: 278.w, height: 48.w, selected: false, onTap: () {
                    Navigator.of(context).pop();
                    if (onCancel != null) onCancel();
                  }),
                ),
              ],
            ),
          );
        });
  }

//弹框顶部居中图片布局
  static Widget _blueToothTopImg(BuildContext context, String imagePath) {
    return Positioned(
      top: 108.w,
      //正则判断，如果图片路径不为空就返回对应的container，否则就返回空的container
      child: imagePath != ""
          ? Container(
              alignment: Alignment.center,
              child: Image.asset(imagePath, height: 68.w, width: 68.w),
            )
          : Container(),
    );
  }

//弹框底部的关闭按钮布局
  static Widget _blueToothClose(BuildContext context) {
    return Positioned(
      bottom: 0,
      child: GestureDetector(
        onTap: () {
          Navigator.of(context).pop();
        },
        child: Image.asset(
          ResUrl.iconImagePath(
            "popclose.png",
          ),
          color: Colors.white,
          width: 45.w,
          height: 45.w,
        ),
      ),
    );
  }
  //可选框
  static Widget _checkboxWidget(bool showCheckbox) {
    bool checked = false;
    return Container(
      child: showCheckbox
          ? Row(
              children: [
                //StatefulBuilder提供了局部更新控件的方法
                StatefulBuilder(
                  builder: (BuildContext context, StateSetter setState) {
                    //可选框
                    return Checkbox(
                        value: checked,
                        checkColor: ResColors.color_FFFFFF,
                        activeColor: ResColors.color_595959,
                        onChanged: (selected) {
                          setState(() => checked = !checked);
                        });
                  },
                ),
                //可选框文字
                Expanded(
                    child: Text(
                  "下次不再提醒",
                  style: TextStyle(color: ResColors.color_595959, fontSize: 14.w),
                ))
              ],
            )
          : Container(),
    );
  }
}


